package com.edu.service;

import com.edu.bean.SubjectInfo;
import com.edu.dao.SubjectInfoDao;

import java.util.*;

public class AdminScheduleService {
    private SubjectInfoDao subjectInfoDao = new SubjectInfoDao();

    /**
     * 获取课程表数据
     * @return Map<String, Map<Integer, List<SubjectInfo>>> 外层Map的key是时间（如"08:00"），内层Map的key是星期几（1-7）
     */
    public Map<String, Map<Integer, List<SubjectInfo>>> getSchedule() {
        // 获取所有课程
        List<SubjectInfo> allSubjects = subjectInfoDao.findAll();

        // 初始化课程表数据结构
        Map<String, Map<Integer, List<SubjectInfo>>> scheduleMap = new HashMap<>();
        String[] timeSlots = {"08:00", "09:00", "10:00", "11:00", "14:00", "15:00", "16:00", "17:00"};

        // 初始化每个时间段的数据
        for (String timeSlot : timeSlots) {
            Map<Integer, List<SubjectInfo>> dayMap = new HashMap<>();
            for (int i = 1; i <= 7; i++) {
                dayMap.put(i, new ArrayList<>());
            }
            scheduleMap.put(timeSlot, dayMap);
        }

        // 将课程放入对应的时间槽
        for (SubjectInfo subject : allSubjects) {
            String classTime = subject.getClassTime().substring(0, 5); // 只取HH:mm部分
            int weekDay = subject.getWeekDay();

            if (scheduleMap.containsKey(classTime)) {
                scheduleMap.get(classTime).get(weekDay).add(subject);
            }
        }

        return scheduleMap;
    }
}